-use std::collections::HashMap;
+use std::collections::{HashMap, HashSet};
use std::dynamic_lib::DynamicLibrary;
use std::ffi::CString;
use std::old_path::BytesContainer;
/// Top-level package that was compiled
pub package: Package,
+
+ /// Features enabled during this compilation.
+ pub features: HashSet<String>,
}
impl Compilation {
binaries: Vec::new(),
extra_env: HashMap::new(),
package: pkg.clone(),
+ features: HashSet::new(),
}
}
let out_dir = cx.layout(pkg, Kind::Target).build_out(pkg)
.display().to_string();
cx.compilation.extra_env.insert("OUT_DIR".to_string(), Some(out_dir));
+
+ if let Some(feats) = cx.resolve.features(pkg.package_id()) {
+ cx.compilation.features.extend(feats.iter().cloned());
+ }
+
for (&(ref pkg, _), output) in cx.build_state.outputs.lock().unwrap().iter() {
let any_dylib = output.library_links.iter().any(|l| {
!l.ends_with(":static") && !l.ends_with(":framework")
p = p.arg("--test-args").arg(test_args.connect(" "));
}
+ for feat in compile.features.iter() {
+ p = p.arg("--cfg").arg(format!("feature=\"{}\"", feat));
+ }
+
for (pkg, libs) in compile.libraries.iter() {
for lib in libs.iter() {
let mut arg = pkg.name().as_bytes().to_vec();
no bin target named `foo` to run
"));
});
+
+test!(doctest_feature {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ [features]
+ bar = []
+ "#)
+ .file("src/lib.rs", r#"
+ /// ```rust
+ /// assert_eq!(foo::foo(), 1);
+ /// ```
+ #[cfg(feature = "bar")]
+ pub fn foo() -> i32 { 1 }
+ "#);
+
+ assert_that(p.cargo_process("test").arg("--features").arg("bar"),
+ execs().with_status(0).with_stdout(format!("\
+{compiling} foo [..]
+{running} target[..]foo[..]
+
+running 0 tests
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
+
+{doctest} foo
+
+running 1 test
+test foo_0 ... ok
+
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
+
+", compiling = COMPILING, running = RUNNING, doctest = DOCTEST)))
+});